#include "single_linklist.h"
#include "double_linklist.h"
#include "loop_linklist.h"

void test_singlelist_head_insert_create_list(SingleLinkList list)
{
    list=SingleLinkListCreateHead();
    SingleLinkListTraverse(list);
}

void test_single_tail_insert_create_list(SingleLinkList list)
{
    list = SingleLinkListCreateTail();
    SingleLinkListTraverse(list);
}

void test_single_getnode(SingleLinkList list)
{
    list = SingleLinkListCreateTail();
    SingleLinkListTraverse(list);
    printf("data=%d\n",SingleLinkListGetnodeNum(list,0)->data);
    printf("data=%d\n",SingleLinkListGetnodeNum(list,1)->data);
    printf("data=%d\n",SingleLinkListGetnodeNum(list,2)->data);
    printf("data=%d\n",SingleLinkListGetnodeData(list,34)->data);
}

void test_single_insert_node(SingleLinkList list)
{
    list = SingleLinkListGenerate();
    SingleLinkListTraverse(list);
    printf("插入数据后\n");
//    insert(list,2,88);
    SingleLinkListAppend(list,999);
    SingleLinkListTraverse(list);
}

void test_single_list_delete(SingleLinkList list)
{
    list=SingleLinkListGenerate();
    SingleLinkListTraverse(list);
//    deleteNode(list,1);
    SingleLinkListDeleteNode(list,2);
    printf("after delete node!\n");
    SingleLinkListTraverse(list);
}

void test_single_list_length(SingleLinkList list)
{
    list=SingleLinkListGenerate();
    SingleLinkListTraverse(list);
    printf("length=%d \n",SingleLinkListGetListLength(list)) ;
}

void test_singlelist()
{
//    SingleLinkList list;
//    test_singlelist_head_insert_create_list(list);
//    test_single_tail_insert_create_list(list);
//    test_single_getnode(list);
//    test_single_insert_node(list);
//    test_single_list_delete(list);
//    test_single_list_length(list);
}

void test_doublelist()
{
    DoubleLinkList list = DoubleLinkListCreate();
    DoubleLinkListGenerateNode(list);
    printf("BEFORE DELETE!\n");
    printf("Length=%d\n",DoubleLinkListGetLength(list));
    DoubleLinkListTraverseNode(list);

    DoubleLinkListDeleteNode(list,3);
    printf("AFTER DELETE!\n");
    printf("Length=%d\n",DoubleLinkListGetLength(list));
    DoubleLinkListTraverseNode(list);
}

void test_looplist()
{
    LoopLinkList list = LoopLinkListNodeCreate();
    LoopLinkListGenerateNode(list);
    printf("LOOPLIST=%d\n",list->prior->prior->data);
    printf("LOOPLIST=%d\n",list->prior->data);
    printf("LOOPLIST=%d\n",list->next->data);
    printf("LOOPLIST=%d\n",list->next->next->data);
    printf("LOOPLIST=%d\n",list->next->next->next->data);
    LoopLinkListTraverNode(list);
}

int main()
{
//    test_singlelist();
//    test_doublelist();
    test_looplist();
    return 0;
}
